package com.key.win.business.chat.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.key.win.business.chat.model.ImGroup;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface ImGroupDao extends BaseMapper<ImGroup> {

    @Select({"SELECT g.* from im_group g where EXISTS (SELECT gu.group_id FROM im_group_user gu where gu.group_Id = g.id and gu.user_id = #{userId} and gu.enable_Flag = 1 )"})
    List<ImGroup> findMyGroup(String userId);

    @Select({"<script>SELECT g.* from im_group g where EXISTS (SELECT gu.group_id FROM im_group_user gu where gu.group_Id = g.id and gu.enable_Flag = 1 and gu.user_id in " +
            " <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'> " +
            " #{item} " +
            " </foreach>" +
            ")</script>"})
    List<ImGroup> findMyGroup(Set<String> userIds);
}
